﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using SES.CMS.BL;

namespace SES.CMS.Module
{
    public partial class ucMainMenu : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                rptMainMenuTopDataSource();
            }
        }

        private void rptMainMenuTopDataSource()
        {
            rptMainMenuTop.DataSource = new cmsMenuBL().SelectMenu(0);
            rptMainMenuTop.DataBind();
        }
        protected void rptMainMenuTop_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                DataRowView drv = (DataRowView)e.Item.DataItem;
                int type = int.Parse(drv["Type"].ToString());
                int parentID = int.Parse(drv["MenuID"].ToString());
                if (type == 1)
                {
                    Panel pnal1 = (Panel)e.Item.FindControl("pnal1");
                    pnal1.Visible = true;
                    Repeater rptMenu1cot = (Repeater)e.Item.FindControl("rptMenu1cot");
                    rptMenu1cot.DataSource = new cmsMenuBL().SelectMenu(parentID);
                    rptMenu1cot.DataBind();
                }
                else if (type == 2)
                {
                    Panel pnal2 = (Panel)e.Item.FindControl("pnal2");
                    pnal2.Visible = true;
                    Repeater rptMenu2CotParent = (Repeater)e.Item.FindControl("rptMenu2CotParent");
                    rptMenu2CotParent.DataSource = new cmsMenuBL().SelectMenu(parentID);
                    rptMenu2CotParent.DataBind();
                }
            }
        }

        protected void rptMenu2CotParent_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                DataRowView drv = (DataRowView)e.Item.DataItem;
                int parentID = int.Parse(drv["MenuID"].ToString());
                Repeater rptMenu2cot = (Repeater)e.Item.FindControl("rptMenu2cot");
                rptMenu2cot.DataSource = new cmsMenuBL().SelectMenu(parentID);
                rptMenu2cot.DataBind();
            }
        }

        protected void rptMainMenuDataSource()
        {
            rptMainMenu.DataSource = new cmsLoaiSanPhamBL().SelectAll(8);
            rptMainMenu.DataBind();
        }

        public string FriendlyUrl(string s)
        {
            return Ultility.Change_AV(s);
        }
    }
}